package com.youdo.careyes.utils;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.util.Log;
import android.view.WindowManager;
import android.widget.ArrayAdapter;

import androidx.fragment.app.FragmentActivity;

import com.youdo.careyes.R;

/**
 * 常用工具
 *
 * @author ljb
 * @date 2025.07.25
 * @email 568838953@qq.com
 */

public class AppUtil {

    /**
     * 保持屏幕常亮
     */
    public static void keepScreenOn(FragmentActivity aty, boolean keepOn) {
        if (keepOn) {
            aty.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        } else {
            aty.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        }
        Log.e("VideoSet", "keepScreenOn: keepOn = " + keepOn);
    }

    /**
     * 最大值和最小值
     */
    public static int constrain(int value, int min, int max) {
        value = Math.max(value, min);
        value = Math.min(value, max);
        return value;
    }

    /**
     * 显示相机处理菜单(在C10A上面没反应,在手机上有反应)
     */
    public static void showVideoDialog(Context context, DialogInterface.OnClickListener listener) {
        final String[] list = context.getResources().getStringArray(R.array.file_menu_list) ;
        ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(context, android.R.layout.simple_list_item_1);
        arrayAdapter.addAll(list);
        new AlertDialog.Builder(context)
                .setAdapter(arrayAdapter, listener)
                .create().show();
    }
}
